package com.gitee.itembucket.util.germ

import com.germ.germplugin.api.dynamic.gui.GermGuiCheckbox
import com.germ.germplugin.api.dynamic.gui.GermGuiScreen
import com.germ.germplugin.api.dynamic.gui.GermGuiScreen.ClickType
import com.gitee.itembucket.util.germ.germ.GermPartDSL
import taboolib.library.configuration.ConfigurationSection

class GermCheckBoxDSL : GermPartDSL<GermGuiCheckbox>() {

    var defaultPath = ""
    var hoverPath = ""
    var checkedPath = ""
    var hoverSound = ""
    var clickSound = ""
    var invalid = false
    var checked = false
    var width = ""
    var height = ""
    var texts = mutableListOf<String>()

    var onclick = mutableMapOf<ClickType, (GermGuiScreen.() -> Unit)>()

    override val type: String = "checkbox"

    override fun infuse(config: ConfigurationSection) {
        name = config.name
        config.getString("locationX")?.let { locationX = it }
        config.getString("locationY")?.let { locationY = it }
        config.getString("locationZ")?.let { locationZ = it }
        config.getString("width")?.let { width = it }
        config.getString("height")?.let { height = it }
        config.getString("defaultPath")?.let { defaultPath = it }
        config.getString("hoverPath")?.let { hoverPath = it }
        config.getString("checkedPath")?.let { checkedPath = it }
        config.getString("clickSound")?.let { clickSound = it }
        invalid = config.getBoolean("invalid")
        checked = config.getBoolean("checked")
        texts += config.getStringList("texts")

        enable = config.getBoolean("enable")
    }


    override fun create(): GermGuiCheckbox {
        return GermGuiCheckbox(name).also {
            it.locationX = locationX
            it.locationY = locationY
            it.locationZ = locationZ
            it.enable = enable
            it.defaultPath = defaultPath
            it.hoverPath = hoverPath
            it.checkedPath = checkedPath
            it.hoverSound = hoverSound
            it.clickSound = clickSound
            it.isInvalid = invalid
            it.checked = checked

            it.width = width
            it.height = height

            it.texts = texts


            onclick.forEach { key, value ->
                it.registerCallbackHandler({ _, _ ->
                    value(it.germGuiScreen)
                }, key)
            }

        }
    }


}